%matplotlib inline
import os
import io
import s3fs
import xarray as xr
import numpy as np
from datetime import datetime
from os.path import isfile, basename, abspath
from pathlib import Path
import matplotlib.pyplot as plt
from matplotlib import animation
from matplotlib.animation import FuncAnimation, PillowWriter
from IPython.display import display, Image, HTML
import hvplot
import hvplot.xarray
import holoviews as hv
from holoviews import opts
import earthaccess
from earthaccess import Auth, DataCollections, DataGranules, Store
hv.extension('bokeh')Working with SWOT Level 2 Water Mask Raster Image Data Product:
Working with SWOT Level 2 Water Mask Raster Image Data Product:
In AWS Cloud Version
Summary & Learning Objectives
Notebook showcasing how to work with SWOT Raster Image data product version 2.0 on a local machine
- Utilizing the earthaccess Python package. For more information visit: https://nsidc.github.io/earthaccess/
- Option to query the new dataset based on users choice; choosing between two resolutions either by ‘100m’ or ‘250m’.
- Visualizing the dataset by choosing one of its various variables.
- Visualizing multiple raster images on a single map.
- Stacking multiple raster images and creating a time dimenstion to analyze over time.
Requirements
1. Compute environment
This tutorial is written to run in the following environment: - AWS instance running in us-west-2: NASA Earthdata Cloud data in S3 can be directly accessed via and s3fs session; this access is limited to requests made within the US West (Oregon) (code: us-west-2) AWS region.
2. Earthdata Login
An Earthdata Login account is required to access data, as well as discover restricted data, from the NASA Earthdata system. Thus, to access NASA data, you need Earthdata Login. Please visit https://urs.earthdata.nasa.gov to register and manage your Earthdata Login account. This account is free to create and only takes a moment to set up.
Import libraries
Authentication with earthaccess
In this notebook, we will be calling the authentication in the below cell.
auth = earthaccess.login(strategy="interactive", persist=True)Search using earthaccess for SWOT Raster products
Each dataset has it’s own unique collection concept ID. For the SWOT_L2_HR_Raster_2.0 dataset, we can find the collection ID here.
For this tutorial, we are looking at the Lake Mead Reservoir.
We used bbox finder to get the exact coordinates for our area of interest.
raster_results = earthaccess.search_data(
short_name = 'SWOT_L2_HR_RASTER_2.0',
bounding_box=(-115.112686,35.740939,-114.224167,36.937819),
temporal =('2024-01-01 00:00:00', '2024-01-05 23:59:59'),
granule_name = '*_100m_*',
count =200
)Granules found: 2
fs_s3 = earthaccess.get_s3fs_session(results=raster_results)Visualizing the Dataset
Let’s now visualize an individual layer for a single file path using Xarray to read the NetCDF image.
raster_link = earthaccess.results.DataGranule.data_links(raster_results[1], access='direct')[0]
s3_file_obj5 = fs_s3.open(raster_link, mode='rb')ds_raster = xr.open_dataset(s3_file_obj5, engine='h5netcdf')
ds_raster<xarray.Dataset>
Dimensions: (x: 1505, y: 1506)
Coordinates:
* x (x) float64 5.931e+05 5.932e+05 ... 7.435e+05
* y (y) float64 4.026e+06 4.026e+06 ... 4.176e+06
Data variables: (12/39)
crs object ...
longitude (y, x) float64 ...
latitude (y, x) float64 ...
wse (y, x) float32 ...
wse_qual (y, x) float32 ...
wse_qual_bitwise (y, x) float64 ...
... ...
load_tide_fes (y, x) float32 ...
load_tide_got (y, x) float32 ...
pole_tide (y, x) float32 ...
model_dry_tropo_cor (y, x) float32 ...
model_wet_tropo_cor (y, x) float32 ...
iono_cor_gim_ka (y, x) float32 ...
Attributes: (12/49)
Conventions: CF-1.7
title: Level 2 KaRIn High Rate Raster Data Product
source: Ka-band radar interferometer
history: 2024-01-05T10:46:43Z : Creation
platform: SWOT
references: V1.1.1
... ...
x_min: 593100.0
x_max: 743500.0
y_min: 4025600.0
y_max: 4176100.0
institution: CNES
product_version: 01ds_raster.wse.hvplot.image(y='y', x='x').opts(width=1000, height=600, colorbar=True)